import { useUserStore } from '../stores/user'

/**
 * 权限指令
 * 用法：v-permission="'user:create'" 或 v-permission="['user:create', 'user:edit']"
 */
export default {
  mounted(el, binding) {
    const userStore = useUserStore()
    const { value } = binding
    
    if (value) {
      const hasPermission = userStore.hasAnyPermission(
        typeof value === 'string' ? [value] : value
      )
      
      if (!hasPermission) {
        // 没有权限则隐藏元素
        el.style.display = 'none'
      }
    } else {
      throw new Error(`需要指定权限值, 例如: v-permission="'user:create'"`)
    }
  }
} 